package article

import (
	"go-gin-api/app/model"
	"go-gin-api/app/util"

	"github.com/gin-gonic/gin"
)

// DeleteArticleByID 根据id删除文章
func DeleteArticleByID(c *gin.Context) *util.Response {
	article := model.Article{}
	if err := model.DB.Where("ID=?", c.Query("id")).Find(&article).Error; err != nil {
		return &util.Response{
			Code:    40000,
			Message: "failed",
			Data:    "此文章不存在!",
		}
	}
	//删除文章
	if err := model.DB.Model(&model.Article{}).Where("ID=?", c.Query("id")).Update("Status", "1").Error; err != nil {
		return &util.Response{
			Code:    40000,
			Message: "failed",
			Data:    "文章删除失败!",
		}
	}
	return &util.Response{
		Code:    200,
		Message: "success",
		Data:    "删除文章成功!",
	}
}
